import { DataBase, DataStructure } from "./database";
import { DeviceList } from "./deviceList";

export enum DeviceModeHandlePath {
    LedTextHandle = 0,
    AutoChanageLedText = 1,
}


/** 设备型号 */
export class DeviceMode extends DataBase {
    public static collectionName: string = "DeviceMode";
    /** 设备名称 */
    public name: string;
    /** 设备型号 */
    public mode: string;
    /** 设备说明 */
    public explain: string;
    /** 设备绑定的页面路径 */
    public bindPath: string;
    /** iconPath */
    public iconPath: string;
    /** 设备操作页面 */
    public handlePath: string[];

    constructor(data: DataStructure = {}) {
        super(data);
        this.name = data['name'] || "";
        this.mode = data['mode'] || "";
        this.explain = data['explain'] || "";
        this.bindPath = data['bindPath'] || "";
        this.iconPath = data['iconPath'] || "";
        this.handlePath = [
            '/pages/device_handle_lononled/index',
            '/pages/device_handle_lononled_auto_change/index'
        ];
    }

    /** 获取所有设备列表 */
    public static async GetDeviceMode() {
        const a = await this.GetAllData({});
        return a.map(x => new DeviceMode(x));
    }

    /** 获取绑定页面 */
    public getBindPath(groupId: string): string {
        return `${this.bindPath}?mode=${this.mode}&_id=${this.get_id()}&groupId=${groupId}`
    }

    /** 获取操作页面路径 */
    public getHandlePath(deviceList: DeviceList, funcName: DeviceModeHandlePath) {
        DeviceList.globalDeviceList = deviceList;
        return `${this.handlePath[funcName]}`
    }
}